<?php
// No directAcces
defined( '_AppBackMiage' ) or die( 'Restricted access' );

include_once (DS."backoffice/include/header.php");
?>
<?php

include_once( DS."backoffice/include/toppanel_stage.php");

?>
<script type="text/javascript">
    function setsignature(id, signataire)
    {
        ajax.setSignatureConvention(id, signataire);
        var cases = signataire+"_"+id;
        $("#"+cases).css('display', 'none');
        $("#"+cases).parent().removeClass().addClass("signe");
    }
    function setdoc(id, idRequireddocument)
    {
        ajax.setRequiredDocument(id, idRequireddocument);
        var cases = idRequireddocument+"_"+id;
        $("#"+cases).css('display', 'none');
        $("#"+cases).parent().removeClass().addClass("signe");
    }
</script>
<div id="wrapper">
    <div id="content">
    	<div id="box">
            <div id="res"></div>
            <?php
            $title = "Conventions";
            ?>
            <h3>Listes des <?php echo $title; ?></h3>
	    <?php
            $nbrResultPerPage = 10;

            if(isset($_GET['page']) && !empty($_GET['page']))
            {
                $page = $_GET['page'];
                $nbr = (((int)$_GET['page']-1)*$nbrResultPerPage);
                $lstStage = Stage::getListConventions($nbrResultPerPage,$nbr);
            }
            else
            {
                $page = 1;
                $lstStage = Stage::getListConventions($nbrResultPerPage,0);
            }
            $count = Stage::globalCount();

            $pages = ceil($count/$nbrResultPerPage);
            $pageSuivante = $page+1;
            $pagePrecendente  = $page-1;
            
            $documents = RequiredDocument::getList();
            $nbdocuments = count($documents);
            if(!empty($lstStage))
            {
            ?>
            <table width="100%">
                <thead>
                    <tr>
                        <th rowspan="2"><a href="#">&Eacute;tudiant</a></th>
                        <th rowspan="2"><a href="#">Promo</a></th>
                        <th rowspan="2"><a href="#">Titre stage</a></th>
                        <th rowspan="2"><a href="#">Date cr&eacute;ation</a></th>
                        <?php
                            if($nbdocuments > 0)
                                echo "<th colspan=".$nbdocuments."><a href='#'>Documents</a></th>";
                        ?>
                        <th colspan="4"><a href="#">Signatures</a></th>
                        <th width="60px" rowspan="2"><a href="#">Action</a></th>
                    </tr>
                    <tr>
                        <?php
                            foreach($documents as $document){
                                echo "<th class='tabsign'>".$document->NomRequiredDocument."</th>";
                            }
                        ?>
                        <th class="tabsign">&Eacute;tudiant</th>
                        <th class="tabsign">Responsable stage</th>
                        <th class="tabsign">UFR</th>
                        <th class="tabsign">Entreprise</th>
                    </tr>
                </thead>
                <tbody>
                <?php foreach( $lstStage as $u){ 
                    $viewURL = URL."/index.php?m=admin_stages_conventions_view&uid=".$u->IdStage;
                    $editURL = URL."/index.php?m=admin_stages_conventions_edit&uid=".$u->IdStage;
                    ?>
                    <tr>
                        <td id="test"><a href="#"><?php echo $u->NomEtudiant.' '.$u->PrenomEtudiant; ?></a></td>
                        <td><?php echo $u->NomPromo; ?></td>
                        <td><?php echo $u->TitreStage; ?></td>
                        <td><?php echo date('j/n/y', $u->DateCreationConvention); ?></td>
                        <?php
                            $docs = RequiredDocument::getListRequiredDocByStage($u->IdStage);
                            if($docs != null && count($docs) == count($documents)){
                                foreach($docs as $d){
                                    if($d->DateUploadDocument)
                                        echo "<td class='signe'></td>";
                                    else
                                        echo "<td class='centre'><input type='checkbox' name='".$d->NomRequiredDocument."' id='".$d->IdRequiredDocument."_".$u->IdStage."' onclick='setdoc(".$u->IdStage.", ".$d->IdRiquierDocument.");'/></td>";
                                }
                            }else {
                                $i = 0;
                                foreach($documents as $d){
                                    if(count($docs) > $i){
                                        if($d->NomRequiredDocument == $docs[$i]->NomRequiredDocument){
                                            if($docs[$i]->DateUploadDocument)
                                                echo "<td class='signe'></td>";
                                            else
                                                echo "<td class='centre'><input type='checkbox' name='".$docs[$i]->NomRequiredDocument."' id='".$docs[$i]->IdRequiredDocument."_".$u->IdStage."' onclick='setdoc(".$u->IdStage.", ".$docs[$i]->IdRequiredDocument.");'/></td>";
                                            $i++;
                                        }else
                                            echo "<td class='centre'><input type='checkbox' name='".$d->NomRequiredDocument."' id='".$d->IdRequiredDocument."_".$u->IdStage."' onclick='setdoc(".$u->IdStage.", ".$d->IdRequiredDocument.");'/></td>";
                                    }else
                                        echo "<td class='centre'><input type='checkbox' name='".$d->NomRequiredDocument."' id='".$d->IdRequiredDocument."_".$u->IdStage."' onclick='setdoc(".$u->IdStage.", ".$d->IdRequiredDocument.");'/></td>";
                                }
                            }
                            if($u->DateSignatureEtudiant)
                                echo "<td class='signe'></td>";
                            else
                                echo "<td class='centre'><input type='checkbox' name='SignatureEtudiant' id='Etudiant_".$u->IdStage."' onclick='setsignature(".$u->IdStage.", \"Etudiant\");'/></td>";
                            if($u->DateSignatureResponsable)
                                echo "<td class='signe'></td>";
                            else
                                echo "<td class='centre'><input type='checkbox' name='SignatureResponsable' id='Responsable_".$u->IdStage."' onclick='setsignature(".$u->IdStage.", \"Responsable\");'/></td>";
                            if($u->DateSignatureUFR)
                                echo "<td class='signe'></td>";
                            else
                                echo "<td class='centre'><input type='checkbox' name='SignatureUFR' id='UFR_".$u->IdStage."' onclick='setsignature(".$u->IdStage.", \"UFR\");'/></td>";
                            if($u->DateSignatureEntreprise)
                                echo "<td class='signe'></td>";
                            else
                                echo "<td class='centre'><input type='checkbox' name='SignatureEntreprise' id='Entreprise_".$u->IdStage."' onclick='setsignature(".$u->IdStage.", \"Entreprise\");'/></td>";
                        ?>
                        <td>
                            <a href="<?php echo $viewURL; ?>">
                            	<img src="<?php echo STYLEBK; ?>img/icons/report.png" title="Voir stage" width="16" height="16" />
                            </a>
                            <a href="<?php echo $editURL; ?>">
                            	<img src="<?php echo STYLEBK; ?>img/icons/page_white_edit.png" title="Editer stage" width="16" height="16" />
                            </a>
                        </td>
                    </tr>
                <?php } ?>
                </tbody>
            </table>
            <div id="pager">
                Page
                <?php if($pagePrecendente > 0): ?>
                	<a href="<?php echo URL."/index.php?m=admin_stages_conventions&page=".$pagePrecendente; ?>"><img src="<?php echo STYLEBK; ?>img/icons/arrow_left.gif" width="16" height="16" /></a>
                <?php endif; ?>
                <?php echo $page; ?>
                <?php if($pageSuivante <= $pages): ?>
                	<a href="<?php echo URL."/index.php?m=admin_stages_conventions&page=".$pageSuivante; ?>"><img src="<?php echo STYLEBK; ?>img/icons/arrow_right.gif" width="16" height="16" /></a>
                <?php endif; ?>
                sur <?php echo $pages; ?> | Total <strong><?php echo $count; ?></strong> stages trouves
            </div>
            <?php
			}
			?>
        </div>
    </div>
<?php
include_once (DS."backoffice/include/sidebar.php");
include_once (DS."backoffice/include/footer.php");
?>

